package com.autcar.training.controller;

import com.autcar.training.entity.Worker;
import com.autcar.training.service.WorkerService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ProjectName: training
 * @Package: com.autcar.training.controller
 * @ClassName: WorkerController
 * @Author: YHHHH
 * @Description: 员工
 * @Date: 2020/8/30 16:02
 * @Version: 1.0
 */
@RestController
public class WorkerController {
    @Resource
    private WorkerService workerService;

    /*
    查询所有的员工
     */
    @RequestMapping("/findAllWorker")
    public List<Worker> findAllWorker(){
        List<Worker> allWorker = workerService.findAllWorker();
        return allWorker;
    }

    /*
    根据姓名查找员工
     */
    @RequestMapping("/WorkerFindByName/{name}")
    public List<Worker> findByName(@PathVariable String name){
        List<Worker> byName = workerService.findByName(name);
        return byName;
    }
    /*
    根据工号找到员工
     */
    @RequestMapping("/WorkerFindById/{id}")
    public Worker findById(@PathVariable Integer id){
        return workerService.findById(id);
    }


    /*
    增加员工
     */
    @RequestMapping("/addWorker")
    public String addWorker(@RequestBody Worker worker){
        int i = workerService.addWorker(worker);
        return null;
    }
    /*
    删除员工
     */
    @RequestMapping("/deleteWorkerById/{id}")
    public String deleteWorkerById(@PathVariable Integer id){
        int i = workerService.deleteWorkerById(id);
        return null;
    }
    /*
    更新员工
     */
    @RequestMapping("/updateWorker")
    public String updateWorker(@RequestBody Worker worker){
        int i = workerService.updateWorker(worker);
        return null;
    }
}
